<?php
$o_db=new class_db_mysql();
$o_db->id="community_list";
$o_db->db_connect(DB_SERVER,DB_DB,DB_USER,DB_PW);
$o_db->rows_per_page=5;

if($_GET["element"]=="community_list" and isset($_GET["page"]))
	$o_db->page=$_GET["page"];

$query="SELECT
wlp_forum.id, 
wlp_forum.headline,
wlp_forum.text,
wlp_forum.time,
wlp_forum.member_id,
wlp_member.member_name,
wlp_member.member_bild,
COUNT(wlp_comments.id) as comments_count
FROM wlp_forum 
JOIN wlp_member ON wlp_member.member_id = wlp_forum.member_id
LEFT JOIN wlp_kalender ON wlp_kalender.forum_id = wlp_forum.id
LEFT JOIN wlp_comments ON wlp_comments.forum_id = wlp_forum.id
GROUP BY wlp_forum.id
ORDER BY time desc";
$data=$o_db->db_query($query);


$pageswitcher = new class_page_switcher($o_db->pages,$o_db,"span",5);
$html_menu_content.=$pageswitcher->get_html();
$user_list = new class_user_list();

$out.="";
foreach($data as $row)
{
/*
	$user=$user_list->get_user($row["member_id"]);
	$post=new class_post();
	$post->id=$row["id"];
	$post->title=$row["headline"];
	$post->datetime=$row["time"];
	$post->text=$row["text"];
	$post->a_author=$user;
*/
	$o_meta=new class_div("");
	$commentbox=new class_div();
	$commentbox->set_attribute("class","commentbox");
	
	
	$comments=new class_link("(".intval($row["comments_count"])." Kommentare)","comment_link_".$row["id"]);
	$comments->set_attribute("href","javascript:jq_show('community_comment.php?id=".$row["id"]."','"."community_comments_".$row["id"]."','"."comment_link_".$row["id"]."');");
	$commentbox->add_item($comments);
	$commentlist=new class_div("");
	$commentlist->set_attribute("id","community_comments_".$row["id"]);
	$commentlist->set_attribute("style","display:none;padding:4px");
	
	
	$o_meta->add_item($commentbox);
	$o_meta->add_item($commentlist);
	
	$personpic=cached_picture("data/gfx/members/".$row["member_id"]."/".$row["member_bild"], $GLOBALS["imgsize"]["memberpic_post"]);
	$personpic->set_attribute("class", "post_member_img");

	
	$out.='
<div class="post">
			<div class="post-bgtop">
				<div class="post-bgbtm">
					<h1 class="title"><a id="title_'.$row["id"].'">'.htmlentities($row["headline"]).'</a></h1>			
					<p class="byline">
						<a href=members.php?id='.$row["member_id"].'>
							'.htmlentities($row["member_name"]).'
						</a> '.strftime("%d. %b %Y :: %X",$row["time"]).'
					</p>
					<div class="entry">
						<p>
						'.$personpic->get_html().'
						'.class_html_element::fulltext($row["text"]).'
						</p>

					</div>
					<div class="meta" id="meta_'.$row["id"].'">
					'.$commentbox->get_html().'
					<div id="community_comments_'.$row["id"].'" style="display:none;padding:4px">
					</div></div>
				</div>
			</div>
		</div>
	
';
}
//$html_main_content.=$out;

$html_main_content='					

				<div class="post">
					<div class="post-bgtop">
						<div class="post-bgbtm">
							<p>
							'.$html_menu_content.'
							</p>
							<div class="entry">
								
							</div>
						</div>
					</div>
				</div>				
'.$out.'

				<div class="post">
					<div class="post-bgtop">
						<div class="post-bgbtm">
							<p>
							'.$html_menu_content.'
							</p>
							<div class="entry">
								
							</div>
						</div>
					</div>
				</div>';			

?>